<template>
  <el-cascader
    :value="value"
    :options="treeData"
    :props="{label:'name',value:'id'}"
    size="small"
    @change="change"
  />
</template>

<script>
import { reqGetDepts } from '@/api/department'
import { translatetoTreeDate } from '@/utils'
export default {
  name: 'SelectTree',
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      treeData: []
    }
  },
  async created() {
    const res = await reqGetDepts()
    this.treeData = translatetoTreeDate(res.data, 0)
  },
  methods: {
    // 级联选择器自带的change事件，自带val
    change(val) {
      // console.log(val)
      // 数据通过父子组件v-model绑定，value获取数据，input提交子组件的数据
      this.$emit('input', val[val.length - 1])
    }
  }
}
</script>

<style>

</style>
